import tools from "@/common/tools.js";
import {
	post
} from '@/common/axios.js';
import {
	messageListApi, //通知列表
	messageDetail, //公告详情
	getbrowsingHistory ,//谁看过我
	interactiveList //我的动态消息
} from '@/common/path.js'
export default {
	//消息
	namespaced: true,
	state: {
		userInfo: uni.getStorageSync('userInfo'),
		messageList: [], //通知列表
		messageData: {}, //公告详情
		browsingList:[],//谁看过我
		activeList:[],//动态消息
	},
	getters: {

	},
	mutations: {
		SET_LIST(state, data) { //消息列表
			state.messageList = data
		},
		SET_DATA(state, data) { //消息详情
			state.messageData = data
		},
		SET_BROWSING_LIST(state, data){  //谁看过我
			state.browsingList = data
		},
		SET_ACTIVE_LIST(state, data){  //动态消息
			state.activeList = data
		}
		
	},
	actions: {
		//谁点赞过- 收藏过  动态消息
		interactiveList({
			dispatch,
			commit,
			state
		},args={}){
			post(interactiveList, args).then(res => {
				if (res.code == 0) {
					if (args.pageNum == 1) {
						commit('SET_ACTIVE_LIST', res.data)
					} else {
						 state.activeList.push(...res.data)
						console.log('[当前数据集]',state.activeList);
						commit('SET_ACTIVE_LIST',state.activeList)
					}
				} else {
					commit('SET_ACTIVE_LIST', [])
				}
			})
		},
		
		//谁看过我
		getbrowsingHistory({
			dispatch,
			commit,
			state
		},args={}){
			post(getbrowsingHistory, args).then(res => {
				if (res.code == 0) {
					if (args.pageNum == 1) {
						commit('SET_BROWSING_LIST', res.data)
					} else {
						 state.browsingList.push(...res.data)
						console.log('[当前数据集]',state.browsingList);
						commit('SET_BROWSING_LIST',state.browsingList)
					}
				} else {
					commit('SET_BROWSING_LIST', [])
				}
			})
		},

		//消息通知列表
		getmessageListApi({
			dispatch,
			commit,
			state
		}, args = {}) {
			post(messageListApi, args).then(res => {
				console.log('[消息]', res);
				if (res.code == 0) {
					if (args.pageNum == 1) {
						commit('SET_LIST', res.data)
					} else {
						state.messageList.push(...res.data)
						commit('SET_LIST', state.messageList)
					}
				} else {
					commit('SET_LIST', [])
				}
			})
		},
		//公告详情
		messageDatailApi({
			commit
		}, args) {
			post(messageDetail, args).then(res => {
				if (res.code == 0) {
					console.log('[详情]', res);
					commit('SET_DATA', res.data)
				} else {
					commit('SET_DATA', {})
				}
			})
		},

	},
}
